
#ifndef GLOBAL_H_
#define GLOBAL_H_

//TESTING
#define BYTE_LED_LSB 2





//WARDEN DEFINES
#define BOUND_POINTS 4
#define DANGER_ZONE_DIST .000075
#define D_UNIT .000037




//GPS DEFINES

#define MAX_GPS_PKTLEN 65
#define MAX_GPS_RECORDS 1

/* some useful defines */
#define START1 0xA0
#define START2 0xA1
#define END1 0x0D
#define END2 0x0A

/* proccessing states */
#define S_RESET 0
#define S_POSTRESET 1
#define S_START1 2
#define S_START2 3
#define S_LENGTH1 4
#define S_LENGTH2 5
#define S_DISCARD 6
#define S_COPY 7
#define S_ENDCOPY 8
#define S_END 9
#define S_END1 10


/* packet types */
/* 0x01 - System Restart */
#define M_RESTART 0x01
typedef struct {
 uint8_t start_mode; /* 01 = Hot; 02 = Warm; 03 = Cold */
 uint16_t utc_year; /* >= 1980 */
 uint8_t utc_month;
 uint8_t utc_day;
 uint8_t utc_hour;
 uint8_t utc_minute;
 uint8_t utc_second;
 int16_t latitude; /* -9000 to 9000, 1/100th degree, positive north */
 int16_t longitude; /* -18000 to 18000, 1/100th degree, positive east */
 int16_t altitude; /* -1000 to 18300, meters */
} m_restart_t;

/* 0x0c - Configure power mode */
#define M_POWERCONF 0x0c
typedef struct {
 uint8_t mode; /* 00 = normal; 01 = power save */
 uint8_t update; /* 00 = SRAM only; 01 = SRAM and FLASH; 02 = temporary */
} m_powerconf_t;

/* 0x0e - Conf position update rate */
#define M_POSHZ 0x0e
typedef struct {
 uint8_t rate; /* 1,2,4,5,8,10 (decimal), rate in Hz */
 uint8_t update; /* 00 = SRAM only; 01 = SRAM and FLASH */
} m_poshz_t;

/* 0x31 - Set ephemeris */
#define M_SETEPH 0x31
typedef struct {
 uint8_t sv; /* sat id */
 uint8_t subframe0[28];
 uint8_t subframe1[28];
 uint8_t subframe2[28];
} m_seteph_t;

/* 0x3b - Configure positioning pinning parameters */
#define M_PINPARACONF 0x3b
typedef struct {
 uint16_t speed; /* km/h */
 uint16_t count; /* seconds */
 uint16_t un_speed; /* km/h */
 uint16_t un_count; /* seconds */
 uint16_t un_dist; /* meters */
} m_pinparaconf_t;

/* 0x83 - ACK */
#define MO_ACK 0x83
typedef struct {
 uint8_t message_type; /* the message being ACKd */
} mo_ack_t;

/* 0x84 - NACK */
#define MO_NACK 0x84
typedef struct {
 uint8_t message_type; /* the message being NACKd */
} mo_nack_t;

/* 0x86 - position update */
#define MO_POSHZ 0x86
typedef struct {
 uint8_t rate; /* see M_POSHZ */
} mo_poshz_t;

/* 0xa8 - navigation data */
#define MO_NAVDATA 0xa8
typedef struct {
 //start1
 //start2
 //len1  //GPS_packet[0]
 //len2
 //pktType
 uint8_t fixmode; /* 0 = none; 1 = 2D, 2 = 3D; 3 = 3D+DGPS */
 uint8_t svnum; /* number of sats in fix */
 uint16_t gps_week; /* GPS Week Number */
 uint32_t gps_tow; /* Time of week, seconds, 1/100th resolution */
 int32_t lattitude; /* 1/1e-7 (???) degree, positive north */
 int32_t longitude; /* 1/1e-7 (???) degree, positive east */
 uint32_t elips_alt; /* meters, 1/100th */
 uint32_t sea_alt; /* meters, 1/100th */
 uint16_t gdop; /* 1/100th */
 uint16_t pdop; /* 1/100th */
 uint16_t hdop; /* 1/100th */
 uint16_t vdop; /* 1/100th */
 uint16_t tdop; /* 1/100th */
 int32_t ecef_x; /* meters, 1/100th */
 int32_t ecef_y; /* meters, 1/100th */
 int32_t ecef_z; /* meters, 1/100th */
 int32_t ecef_vx; /* meters, 1/100th */
 int32_t ecef_vy; /* meters, 1/100th */
 int32_t ecef_vz; /* meters, 1/100th */
} mo_navdata_t;

#endif